package com.mico.example.springboot.exception.handler.handler;

import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by micocube
 * ProjectName: springboot-example
 * PackageName: com.mico.example.springboot.exception.handler.handler
 * User: micocube
 * Email: ldscube@gmail.com
 * CreateTime: 2019-03-0814:36
 * ModifyTime: 2019-03-0814:36
 * Version: 0.1
 * Description: 如果是普通的控制器可以用ControllerAdvice
 **/
@RestControllerAdvice
public class ExceptionHandler {
    @org.springframework.web.bind.annotation.ExceptionHandler(value = Exception.class)
    public ExceptionBody handler(HttpServletRequest request,
                                           Exception exception) {
        String message = exception.getMessage();
        ExceptionBody exceptionBody = new ExceptionBody(message);
        return exceptionBody;
    }
}
